const App = {
    mixins: [Query],//配置文件，路径/utils/mixins.js
    data() {
        return {
            page: {
                value1: '',
                activeName: 'first',
                Row_Status: '',
                PageNumber: 1, //页码
                RowAmount: 10,
                Condition: window.btoa(unescape(encodeURIComponent("%%,%%"))),
                ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND (district_introduction.District_Number IN (" + getCookie('village') + ") OR district_introduction.District_Number IN (" + getCookie('town') + ")) \r\n"))),
            },
            ProvinceNumber: ''
        }
    },
    mounted() {

    },
    methods: {
        check() {
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%" + this.page.Row_Status + "%")));
            this.postgetList(this.page)
        },
        handleClick() {
            if (this.page.activeName == 'first') {
                this.page.Row_Status = '';
            } else if (this.page.activeName == 'second') {
                this.page.Row_Status = '0';
            } else if (this.page.activeName == 'third') {
                this.page.Row_Status = '2';
            }
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%" + this.page.Row_Status + "%")));
            this.postgetList(this.page)
        },
        Treedata() {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/permissionsTree/getDistrictTreeByPermissions`,
                type: "GET",
                data: {
                  DistrictCode: getCookie('village'), //请求参数
                },
                success:  (data)=> {
                  this.treeData = data;
                },
                complete: (XMLHttpRequest) => {
                  requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        //树的点击筛选事件
        handleNodeClick(data, node) {
            this.ProvinceNumber = data.ProvinceNumber;
            this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND district_introduction.District_Number = '" + this.ProvinceNumber + "'")));
            this.postgetList(this.page)
        },
        personalAdd() {
            window.location.href = "./add.html?action=Add" + (this.ProvinceNumber ? ("&ProvinceNumber=" + this.ProvinceNumber) : '');
        },
        handleTab(row) {
            this.$confirm('是否' + (row.Row_Status == '2' ? '生效' : '取消生效') + '该数据', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                let { TableName, primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                    method: "post",
                    data: {
                        Data: TableName,
                        Condition: primary_key + "='" + row[primary_key] + "'" + (row.Row_Status == '2' ? (" OR (District_Number='" + row['District_Number'] + "' AND Row_Status='0')") : '')
                    },
                    success: (res) => {
                        if (res.length >= 1) {
                            if (row.Row_Status == '2') {
                                res.filter(i => i.Row_Status_Original == '0').forEach(item => {
                                    item.Row_Status = '2'
                                });
                                res.filter(i => i.Row_Status_Original == '2').forEach(item => {
                                    item.Row_Status = '0'
                                });
                            } else {
                                res[0].Row_Status = '2';
                            }
                            let lJSONObject_DataSet = new Object();
                            let lJSONObject_Table = new Object();
                            lJSONObject_Table[TableName] = res;
                            lJSONObject_DataSet['Modify'] = lJSONObject_Table;
                            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                            if (!lJSONObject_DataSet['Add']) {
                                lJSONObject_DataSet['Add'] = new Object();
                            }
                            lJSONObject_DataSet['Add']['base_operation_log'] = [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main,
                                Operation_Interface: "generalSave",
                                Operation_IP: getIpAddress()
                            }]
                            submitSave(lJSONObject_DataSet,(res)=>{
                                if (res.Status == 'success') {
                                    this.postgetList(this.page);
                                } else {
                                    this.$message({
                                        type: 'error',
                                        message: '操作失败'
                                    });
                                }
                            })
                            // $.ajax({
                            //     headers: requestHeaders(),
                            //     url: `${mh}/generalBusiness/generalSave`,
                            //     method: "post",
                            //     data: {
                            //         Data: JSON.stringify(lJSONObject_DataSet),
                            //     },
                            //     success: (res) => {
                            //         if (res.Status == 'success') {
                            //             this.postgetList(this.page);
                            //         } else {
                            //             this.$message({
                            //                 type: 'error',
                            //                 message: '操作失败'
                            //             });
                            //         }
                            //     },
                            //     complete: (XMLHttpRequest) => {
                            //         requestPretreatment(XMLHttpRequest);
                            //     },
                            // });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '操作失败'
                            });
                        }

                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                });
            }).catch(() => { });
        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
